import pyscreeze

import Config
from driver.driver import *
from public.public import get_soldier_cities, entry_city


def main():
    control = get_control_by_level([0, 0, 0, 0, 0, 0], base_name="热血三国-")
    left, top, width, height = get_control_position(control)

    cities = get_soldier_cities(control)
    for _ in cities:
        entry_city(left, top, _[0], _[1], cityin=True)
        first_city = _ == cities[0]
        # 点击仓库
        _ = Config.ChengNeiConfig.Warehouse
        mouse_move_to_and_click(left + _[0], top + _[1])

        # 点击打包按钮
        _ = Config.Warehouse.DaBaoButton
        mouse_move_to_and_click(left + _[0], top + _[1])

        # 打包粮食
        if first_city:
            _ = Config.Warehouse.FoodBoxTypePullButton
            mouse_move_to_and_click(left + _[0], top + _[1])
            time.sleep(0.1)
            mouse_move_to_and_click(left + _[0], top + _[1] + 40)
        _ = Config.Warehouse.FoodMaxButton
        mouse_move_to_and_click(left + _[0], top + _[1])

        # 打包木材
        if first_city:
            _ = Config.Warehouse.WoodBoxTypePullButton
            mouse_move_to_and_click(left + _[0], top + _[1])
            time.sleep(0.1)
            mouse_move_to_and_click(left + _[0], top + _[1] + 40)
        _ = Config.Warehouse.WoodMaxButton
        mouse_move_to_and_click(left + _[0], top + _[1])

        # 打包石料
        if first_city:
            _ = Config.Warehouse.MineBoxTypePullButton
            mouse_move_to_and_click(left + _[0], top + _[1])
            time.sleep(0.1)
            mouse_move_to_and_click(left + _[0], top + _[1] + 40)
        _ = Config.Warehouse.MineMaxButton
        mouse_move_to_and_click(left + _[0], top + _[1])

        # 打包粮铁锭
        if first_city:
            _ = Config.Warehouse.IronBoxTypePullButton
            mouse_move_to_and_click(left + _[0], top + _[1])
            time.sleep(0.1)
            mouse_move_to_and_click(left + _[0], top + _[1] + 40)
        _ = Config.Warehouse.IronMaxButton
        mouse_move_to_and_click(left + _[0], top + _[1])

        # 确认打包
        _ = Config.Warehouse.DaBaoSureButton
        mouse_move_to_and_click(left + _[0], top + _[1])

        # 关闭打包操作
        time.sleep(1)
        _ = pyautogui.locateOnScreen("./imgs/CloseButton3.jpg", confidence=0.95)
        _ = pyscreeze.center(_)
        mouse_move_to_and_click(_[0], _[1])
        _ = Config.Warehouse.CloseButton2
        mouse_move_to_and_click(left + _[0], top + _[1])
        _ = Config.Warehouse.CloseButton1
        mouse_move_to_and_click(left + _[0], top + _[1])


if __name__ == "__main__":
    main()
    # _ = pyautogui.locateOnScreen("./imgs/CloseButton3.jpg", confidence=0.95)
    # _ = pyscreeze.center(_)
    # control = get_control_by_level([0, 0, 0, 0, 0, 0], base_name="热血三国-")
    # left, top, width, height = get_control_position(control)
    # mouse_move_to_and_click(_[0], _[1])
